package com.lzq.leetcode.lanqiao;

import java.util.Scanner;

public class s1135 {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
        int N = scan.nextInt();
        int M = scan.nextInt();
        DSet set = new DSet(N);
        for (int i=0; i<M; i++) {
            int op = scan.nextInt();
            int a = scan.nextInt();
            int b = scan.nextInt();
            if (op == 1) {
                set.add(a, b);
            } else {
                System.out.println(set.equal(a, b) ? "YES" : "NO");
            }

        }
        scan.close();
    }

    static class DSet {
        int[] arr = null;
        int len;
        DSet(int len) {
            arr = new int[len+1];
            for (int i=1; i<=len; i++) {
                arr[i] = i;
            }
        }

        int getRoot(int a) {
            int root = a;
            if (arr[a] != a) {
                root = getRoot(arr[a]);
                arr[a] = root;
            }
            return root;
        }

        void add(int a, int b) {
            int rootA = getRoot(a);
            int rootB = getRoot(b);
            arr[rootB] = rootA;
        }

        boolean equal(int a, int b) {
            return getRoot(a) == getRoot(b);
        }
    }
}
